﻿using InvestmentIntelligence.SchedulingService.Infrastructure;
using InvestmentIntelligence.TradingData.Adapters.Mus.DataGenerators;
using System.Collections.Generic;
using System.ComponentModel.Composition;

namespace InvestmentIntelligence.TradingData.Adapters.Mus.HandlerFactories
{
    [Export(typeof(IScheduledTaskFactory))]
    [ExportMetadata("TaskName", "GenerateTradingDataOutput")]
    public class MusTradingDataOutputGeneratorHandlerFactory : FolderBasedHandlerFactoryBase, IScheduledTaskFactory
    {
        private readonly ScheduledTaskParameter _outputFolder = new StringScheduledTaskParameter(
            "output-dir", "specifies a directory to output trading data");

        private readonly ScheduledTaskParameter _positionsMask = new StringScheduledTaskParameter(
            "positions-mask", "specifies a mask of position files");

        private readonly ScheduledTaskParameter _tradesMask = new StringScheduledTaskParameter(
            "trades-mask", "specifies a mask of trades files");

        private readonly ScheduledTaskParameter _capitalsMask = new StringScheduledTaskParameter(
            "capitals-mask", "specifies a mask of capitals files");

        private readonly ScheduledTaskParameter _rimesUser = new StringScheduledTaskParameter(
            "rimes-user", "specifies a rimes user");

        private readonly ScheduledTaskParameter _rimesPassword = new StringScheduledTaskParameter(
            "rimes-password", "specifies a rimes password");

        private readonly ScheduledTaskParameter _dateMask = new StringScheduledTaskParameter(
           "date-mask", "specifies a mask of date field");

        public override IEnumerable<ScheduledTaskParameter> GetParameters()
        {
            yield return _outputFolder;
            yield return _positionsMask;
            yield return _tradesMask;
            yield return _capitalsMask;
            yield return _rimesUser;
            yield return _rimesPassword;
            yield return _dateMask;
        }

        public override IScheduledTask CreateTask(CreateTaskParams createTaskParams, IDictionary<ScheduledTaskParameter, string> arguments)
        {
            const int bookId = 2; //todo: add parameter
            var outputDir = _outputFolder.Get(arguments, string.Empty);
            var positionsMask = _positionsMask.Get(arguments, string.Empty);
            var tradesMask = _tradesMask.Get(arguments, string.Empty);
            var capitalsMask = _capitalsMask.Get(arguments, string.Empty);
            var dateMask = _dateMask.Get(arguments, string.Empty);

            return new TradingDataOutputGenerator(bookId, outputDir, positionsMask, tradesMask, capitalsMask, dateMask);
        }
    }
}
